package com.crazyauntzhang.easyshopbackend.service;

import com.crazyauntzhang.easyshopbackend.dao.UserDao;
import com.crazyauntzhang.easyshopbackend.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class UserService {

	private final UserDao userDao;

	@Autowired
	public UserService(UserDao userDao) {
		this.userDao = userDao;
	}

	public List<User> findAllUsers() {
		return userDao.selectAllUsers();
	}

	public User findUserById(String userID, Boolean isOnJob) {
		return userDao.selectUserById(userID, isOnJob);
	}

	public List<User> findUserByName(String username, Boolean isOnJob) {
		return userDao.selectUserByName(username, isOnJob);
	}

	public void addUser(String userID,
						String username,
						String password,
						String roleID,
						Boolean isOnJob,
						String tel,
						LocalDate hireDate) {
		userDao.insertUser(userID, username, password, roleID, isOnJob, tel, hireDate);
	}

	public Integer findEmployeeCount() {
		return userDao.selectEmployeeCount();
	}

	public User findUserOnJob(String userID) {
		return userDao.selectUserOnJob(userID);
	}

	public void changeUserOffJob(String userID) {
		userDao.updateUserOffJob(userID);
	}

	public void changeUser(String userID, String newUserID, String username, String password, String roleID, Boolean isOnJob, String tel, LocalDate hireDate) {
		userDao.updateUser(userID, newUserID, username, password, roleID, isOnJob, tel, hireDate);
	}
}
